package com.ruoyi.project.jiaqin.mcooperate.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.jiaqin.mcooperate.domain.Cooperate;
import com.ruoyi.project.jiaqin.mcooperate.service.ICooperateService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 我要合作Controller
 * 
 * @author admin
 * @date 2021-02-02
 */
@Controller
@RequestMapping("/jiaqin/mcooperate")
public class CooperateController extends BaseController
{
    private String prefix = "jiaqin/mcooperate";

    @Autowired
    private ICooperateService cooperateService;

    @RequiresPermissions("jiaqin:mcooperate:view")
    @GetMapping()
    public String mcooperate()
    {
        return prefix + "/mcooperate";
    }

    /**
     * 查询我要合作列表
     */
    @RequiresPermissions("jiaqin:mcooperate:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(Cooperate cooperate)
    {
        startPage();
        List<Cooperate> list = cooperateService.selectCooperateList(cooperate);
        return getDataTable(list);
    }

    /**
     * 导出我要合作列表
     */
    @RequiresPermissions("jiaqin:mcooperate:export")
    @Log(title = "我要合作", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(Cooperate cooperate)
    {
        List<Cooperate> list = cooperateService.selectCooperateList(cooperate);
        ExcelUtil<Cooperate> util = new ExcelUtil<Cooperate>(Cooperate.class);
        return util.exportExcel(list, "mcooperate");
    }

    /**
     * 新增我要合作
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存我要合作
     */
    @RequiresPermissions("jiaqin:mcooperate:add")
    @Log(title = "我要合作", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(Cooperate cooperate)
    {
        return toAjax(cooperateService.insertCooperate(cooperate));
    }

    /**
     * 修改我要合作
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        Cooperate cooperate = cooperateService.selectCooperateById(id);
        mmap.put("cooperate", cooperate);
        return prefix + "/edit";
    }

    /**
     * 修改保存我要合作
     */
    @RequiresPermissions("jiaqin:mcooperate:edit")
    @Log(title = "我要合作", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(Cooperate cooperate)
    {
        return toAjax(cooperateService.updateCooperate(cooperate));
    }

    /**
     * 删除我要合作
     */
    @RequiresPermissions("jiaqin:mcooperate:remove")
    @Log(title = "我要合作", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(cooperateService.deleteCooperateByIds(ids));
    }
}
